<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>交换两节点位置</title>
</head>

<body>
    <ul>
        <li>1</li>
        <li>2</li>
        <li>3</li>
        <li>4</li>
        <li>5</li>
    </ul>
    <button>exchange</button>
    <script>

        // (function () {
        //     let list = document.querySelectorAll("ul > li")
        //     list[0].parentNode.insertBefore(list[4], list[0])
        //     list[0].parentNode.append(list[0]);
        // })();
        let list = document.querySelectorAll('ul > li')
        let btn = document.querySelector('button')
        btn.addEventListener('click',() => {
            list[0].parentNode.insertBefore(list[4],list[0])
            list[0].parentNode.append(list[0])
        })
    </script>
</body>

</html>